Solving 10385 - Duathlon (Ternary search)
[andmenj-acm.git] / 10573 - Geometry paradox / 10573.cpp
blobd279cdb8638e5c28a8fbc665b88df69f7befd1d4
1 /*
2 Problem: 10573 - Geometry Paradox (UVa)
3 */
4 using namespace std;
5 #include <algorithm>
6 #include <iostream>
7 #include <iterator>
8 #include <sstream>
9 #include <fstream>
10 #include <cassert>
11 #include <climits>
12 #include <cstdlib>
13 #include <cstring>
14 #include <string>
15 #include <cstdio>
16 #include <vector>
17 #include <cmath>
18 #include <queue>
19 #include <deque>
20 #include <stack>
21 #include <list>
22 #include <map>
23 #include <set>
25 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
26 #define D(x) cout << #x " is " << x << endl
27 #define For(i, a, b) for (int i=(a); i<(b); ++i)
29 int main(){
30 int n;
31 cin >> n;
32 string s;
33 getline(cin, s);
34 while (n-- && getline(cin, s)){
35 int r1, r2;
36 if (sscanf(s.c_str(), "%d %d", &r1, &r2) == 2){
37 printf("%.4lf\n", 4*acos(0)*r1*r2);
38 }else{
39 int t;
40 sscanf(s.c_str(), "%d", &t);
41 printf("%.4lf\n", acos(0)*t*t/4);
44 return 0;
48 If you are given r1 and r2, then the gray area is
49 the area of the big circle minus the area of the small circles:
51 pi * ((r1 + r1)² - r1² - r2²)) = 2 * pi * r1 * r2
53 If you are given t, you can form a rectangular triangle where the cathetuses
54 are (t/2) and k, and the hypothenuse is (r1 + r2). Then, k = (r1 - r2).
55 Solve the pythagorean theorem for this triangle and you should get
57 r1 * r2 = t² / 16
59 Replace r1 * r2 in the formula above and you will get
60 2 * pi * r1 * r2 = 2 * pi * (t² / 16) = pi * t² / 8